package com.yaokai.rabbit.demo06.priority;

import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.Channel;
import com.yaokai.rabbit.utils.RabbitMqUtils;

import java.nio.charset.StandardCharsets;

public class PriorityProducer {

    private static final String QUEUE_NAME = "hello";

    public static void main(String[] args) throws Exception {
        Channel channel = RabbitMqUtils.getChannel();

        //给消息赋予一个priority属性
        AMQP.BasicProperties properties = new AMQP.BasicProperties().builder().priority(5).build();

        for (int i = 0; i < 11; i++) {
            String message = "info"+i;
            channel.basicPublish("",QUEUE_NAME,i==6?properties:null,message.getBytes(StandardCharsets.UTF_8));
            System.out.println("发送消息："+message+"完成");
        }

    }

}
